<?php
class article_Mapper extends content_Mapper{
    private $selectStmt;
    private $updateStmt;
    private $insertStmt;
  
    function  __construct() {
        parent::__construct();
        $this->selectStmt = self::$PDO->prepare(
            "SELECT * FROM article WHERE articleId = ?");
        $this->updateStmt = self::$PDO->prepare(
            'UPDATE article SET
                articleAddDate =?,
                articleOwner =?,
                articleActiv =?,
                articleKeywords=?,
                articleTitle=?,
                articleBody=?
             WHERE  articleId=?');
        $this->insertStmt = self::$PDO->prepare(
            'INSERT into article SET
                articleAddDate =?,
                articleOwner =?,
                articleActiv =?,
                articleKeywords=?,
                articleTitle=?,
                articleBody=?');
       


    }

   
    function update($obj){
        $values = array(
            $obj->getAddData(),
            $obj->getOwner(),
            $obj->getActiv(),
            $obj->getKeywords(),
            $obj->getTitle(),
            $obj->getBody(),
            $obj->getId()
        );        
        $this->updateStmt->execute( $values );
        return $obj;
    }
    
    protected function doInsert($obj){
        $values = array(
            $obj->getAddData(),
            $obj->getOwner(),
            $obj->getActiv(),
            $obj->getKeywords(),
            $obj->getTitle(),
            $obj->getBody()
        );
        $this->insertStmt->execute( $values );
        $obj->setId(self::$PDO->lastInsertId());
        return $obj;
    }

    protected  function doCreateObject( array $array ){        
        $obj = new articleObject();
        $obj->setId($array['articleId']);
        $obj->setAddData($array['articleAddDate']);
        $obj->setOwner($array['articleOwner']);
        $obj->setActiv($array['articleActiv']);
        $obj->setKeywords($array['articleKeywords']);
        $obj->setTitle($array['articleTitle']);
        $obj->setBody($array['articleBody']);
        return $obj;
    }
   /* public function save($object){
        if($object->getId() < 1){
            return $this->doInsert($object);
        } else {
            return $this->update($object);
        }
    }*/
    protected  function targetClass(){
        return 'article';
    }
    protected  function selectStmt(){
        return $this->selectStmt;

    }
}

class article_Mapper_Collection extends content_Mapper_Collection{
    function targetClass(){
        return 'article';
    }
}
?>
